﻿using Furion.DynamicApiController;
using StackExchange.Redis;
using WesWebCore;

namespace WesJob.Counter;

public class CounterService : IDynamicApiController
{
    private readonly IConnectionMultiplexer _redisConnection;

    public CounterService(IConnectionMultiplexer redisConnection)
    {
        _redisConnection = redisConnection;
    }

    public async Task<long> Get()
    {
        var db = _redisConnection.GetDatabase();

        return long.TryParse(await db.StringGetAsync(RedisKeys.Counter), out var val) ? val : 0;
    }
}
